from odoo import models, fields, _


# 审批流类
class Workflow(models.Model):
    _inherit = 'sb.workflow'

    workflow_type = fields.Selection(selection_add=[
        ('coding_template', 'Coding Template'),
    ], ondelete={'activity': 'cascade'})
    # 关联销售单据
    product_coding_id = fields.Many2one('product.coding.template', string="Product Coding Template", ondelete="cascade")


class WorkflowItem(models.Model):
    _inherit = 'sb.workflow.item'

    def pass_approve(self):
        if self.state == 'pass':
            return
        self.env['workflow.check.wizard'].create([{'sb_workflow_item_id': self.id,
                                                   'planned_receiving_date': False,
                                                   'approval_instructions': '审批通过'}]).approval_pass()

    def reject_approve(self):
        self.env['workflow.check.wizard'].create([{'sb_workflow_item_id': self.id,
                                                   'planned_receiving_date': False,
                                                   'approval_instructions': '审批驳回'}]).approval_no_pass()

    def coding_reject(self):
        # self.approval_no_pass()
        return {
            'name': _('Product Coding Template Action'),
            'type': 'ir.actions.act_window',
            'res_model': 'product.coding.template',
            'view_mode': 'tree',
            'target': 'new',
        }
